/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.poli.view;

import co.poli.utilidades.AdapterPanel;
import co.poli.utilidades.ReporteServicio;
import co.poli.utilidades.Util;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/**
 *
 * @author user
 */
public class JMainMenu extends javax.swing.JFrame {

    AdapterPanel adapter;
    Dimension dim;
    Errores componente;
    ReporteServicio reporte;
    Util util;

    /**
     * Creates new form JMainMenu
     */
    public JMainMenu() {

        util = Util.getInstance();
        initComponents();
        cargarImagen(this.jDesktopPane1);
        dim = this.getToolkit().getScreenSize();
        this.setSize(dim);
    }

    @Override
    public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("co/poli/recursos/imagenes/help_icon_inicio.png"));
        return retValue;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        btnSalir = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jmSoporte = new javax.swing.JMenu();
        itemSoporte = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jmAyuda = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("INFRASOFT");
        setFocusCycleRoot(false);
        setIconImage(getIconImage());

        jDesktopPane1.setBackground(new java.awt.Color(153, 153, 153));
        jDesktopPane1.setOpaque(false);

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/logout-icon.png"))); // NOI18N
        btnSalir.setToolTipText("Cerrar sesión");
        btnSalir.setContentAreaFilled(false);
        btnSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btnSalirMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btnSalirMouseExited(evt);
            }
        });

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap(980, Short.MAX_VALUE)
                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap(386, Short.MAX_VALUE)
                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jDesktopPane1.setLayer(btnSalir, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jMenuBar1.setToolTipText("Seleccione una opción");
        jMenuBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jMenuBar1.setOpaque(false);

        jmSoporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/config-icon.png"))); // NOI18N
        jmSoporte.setToolTipText("Mantenimiento y soporte");
        jmSoporte.setInheritsPopupMenu(true);
        jmSoporte.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jmSoporte.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jmSoporte.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jmSoporteMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jmSoporteMouseExited(evt);
            }
        });
        jmSoporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmSoporteActionPerformed(evt);
            }
        });

        itemSoporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/document-help-icon.png"))); // NOI18N
        itemSoporte.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                itemSoporteMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                itemSoporteMouseExited(evt);
            }
        });
        itemSoporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemSoporteActionPerformed(evt);
            }
        });
        jmSoporte.add(itemSoporte);

        jMenuBar1.add(jmSoporte);

        jMenu1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/Adobe-PDF-Reader-Book-icon.png"))); // NOI18N
        jMenu1.setToolTipText("Informes de la aplicación");
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jMenu1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jMenu1MouseExited(evt);
            }
        });
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/Misc-Web-Database-icon.png"))); // NOI18N
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jMenuItem3MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jMenuItem3MouseExited(evt);
            }
        });
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jmAyuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/Acerca_icon.png"))); // NOI18N
        jmAyuda.setToolTipText("Ayuda de la aplicación");
        jmAyuda.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jmAyudaMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jmAyudaMouseExited(evt);
            }
        });

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/poli/recursos/imagenes/App-hardware-info-icon.png"))); // NOI18N
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jMenuItem2MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jMenuItem2MouseExited(evt);
            }
        });
        jmAyuda.add(jMenuItem2);

        jMenuBar1.add(jmAyuda);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void itemSoporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemSoporteActionPerformed

        try {
            // TODO add your handling code here:

            /**
             * validamos si el objeto existe en memoria
             *
             */
            if (!(componente instanceof Errores)) {
                componente = new Errores();
            }
            /**
             * Validamos si el internalframe ya se abrio una vez
             */
            if (!componente.isShowing()) {
                componente = new Errores();

                jDesktopPane1.add(componente);
                componente.setVisible(true);
                componente.setSelected(true);
                util.CentrarVentanaInterna(componente, jDesktopPane1);
            }

        } catch (PropertyVetoException ex) {
            JOptionPane.showInternalMessageDialog(jDesktopPane1, "Error iniciando el item Errores " + ex.getMessage());
        }


    }//GEN-LAST:event_itemSoporteActionPerformed

    private void jmSoporteMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmSoporteMouseEntered
        // TODO add your handling code here:

        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    }//GEN-LAST:event_jmSoporteMouseEntered

    private void itemSoporteMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemSoporteMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_itemSoporteMouseEntered

    private void jMenu1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_jMenu1MouseEntered

    private void jMenuItem3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_jMenuItem3MouseEntered

    private void jmAyudaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmAyudaMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_jmAyudaMouseEntered

    private void jMenuItem2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_jMenuItem2MouseEntered

    private void jmSoporteMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmSoporteMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jmSoporteMouseExited

    private void itemSoporteMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemSoporteMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_itemSoporteMouseExited

    private void jMenu1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jMenu1MouseExited

    private void jMenuItem3MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jMenuItem3MouseExited

    private void jmAyudaMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmAyudaMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jmAyudaMouseExited

    private void jMenuItem2MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jMenuItem2MouseExited

    private void btnSalirMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSalirMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_btnSalirMouseEntered

    private void btnSalirMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSalirMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_btnSalirMouseExited

    private void jmSoporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmSoporteActionPerformed


    }//GEN-LAST:event_jmSoporteActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:


    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        /**
         * validamos si el objeto existe en memoria
         *
         */
        if (!(reporte instanceof ReporteServicio)) {
            reporte = new ReporteServicio(this.jDesktopPane1);
        }
        /**
         * Validamos si el internalframe ya se abrio una vez
         */
        if (!reporte.isShowing()) {
            try {
                reporte = new ReporteServicio(this.jDesktopPane1);
                jDesktopPane1.add(reporte);
                reporte.setVisible(true);
                reporte.setSelected(true);
                util.CentrarVentanaInterna(reporte, jDesktopPane1);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(JMainMenu.class.getName()).log(Level.SEVERE, null, ex);
            }
        }


    }//GEN-LAST:event_jMenuItem3ActionPerformed

    /*este metodo recibe el jdeskopPane y el archivo imagen*/
    public void cargarImagen(javax.swing.JDesktopPane jDeskp) {
        try {
            BufferedImage image;

            URL path = getClass().getResource("/co/poli/recursos/imagenes/Settings-icon.png");
            image = ImageIO.read(path);
            adapter = AdapterPanel.getInstance(image);
            jDeskp.setBorder(adapter);
        } catch (IOException e) {
            System.out.println("Error cargando la imagen");
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSalir;
    private javax.swing.JMenuItem itemSoporte;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenu jmAyuda;
    private javax.swing.JMenu jmSoporte;
    // End of variables declaration//GEN-END:variables
}
